import { PageParam } from '@/services/common'
import { covertTableData } from '@/utils/tableUtil'
import { request } from '@umijs/max'

export interface PosterVO {
  /**
   * 海报id
   */
  id: string
  fileName: string
  /**
   * 链接地址
   */
  picUrl: string
  /**
   * 排序
   */
  sort: number
  /**
   * 租户id
   */
  tenantId: string
}

export interface PosterQueryDTO extends PageParam {
  /**
   * 海报id
   */
  id: string
  /**
   * 链接地址
   */
  picUrl: string
  /**
   * 排序
   */
  sort: number
  /**
   * 租户id
   */
  tenantId: string
}

export interface PosterUpdateDTO {
  /**
   * 海报id
   */
  id?: string
  fileName: string
  /**
   * 链接地址
   */
  picUrl?: string
  /**
   * 排序
   */
  sort?: number
}

export const getPosterById = async (id: string) => {
  return request<PosterVO>(`/api/poster?id=${id}`, { method: 'GET' })
}

export const getPosterList = async (params: PosterQueryDTO) => {
  return request<Array<PosterVO>>(`/api/poster/list`, { method: 'GET', params })
}

export const getPosterPage = async (params: PosterQueryDTO) => {
  let response = await request<Array<PosterVO>>(`/api/poster/page`, { method: 'GET', params })
  return covertTableData(response)
}

export const updatePoster = async (posterUpdateDTO: PosterUpdateDTO) => {
  return request<PosterVO>(`/api/poster/update`, { method: 'POST', data: posterUpdateDTO })
}

export const savePoster = async (posterUpdateDTO: PosterUpdateDTO) => {
  return request<PosterVO>(`/api/poster/save`, { method: 'POST', data: posterUpdateDTO })
}

export const removePoster = async (id: string) => {
  return request<boolean>(`/api/poster/remove?id=${id}`, { method: 'POST' })
}
